﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;


namespace BestLifePOS_Core.Data.Commands
{
    class BestLifePoDetailsByPoIdDataAction  : BestLifeDataAction<DataTable>
    {


        private string GvPOId;
        public BestLifePoDetailsByPoIdDataAction(string PPoId)
        {
            GvPOId = PPoId;
        }

        public override DataTable Body(SqlConnection PConn)
        {
            try
            {
                //List<Purchase_Order> LvList = new List<Purchase_Order>();
                ///////datatable
                DataTable LvTable2 = new DataTable();
                LvTable2.Columns.Add("PONo ");
                LvTable2.Columns.Add("PLId ");
                LvTable2.Columns.Add("PurchasePrice ");
                LvTable2.Columns.Add("ProductId ");
                LvTable2.Columns.Add("ProductName ");
                LvTable2.Columns.Add("Qty ");


                //////////

                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetPoDetailsByPoId";
                LvCommand.Parameters.Add(new SqlParameter("@PoID", GvPOId));//when passing parameters to the SP

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    //Object LvPos = new Object();

                LvTable2.Rows.Add(LvTable2.NewRow());

                LvTable2.Rows[LvTable2.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                string Lvtext = LvReader.GetValue(0).ToString();
                LvTable2.Rows[LvTable2.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                LvTable2.Rows[LvTable2.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                LvTable2.Rows[LvTable2.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
                LvTable2.Rows[LvTable2.Rows.Count - 1][4] = LvReader.GetValue(4).ToString();
                LvTable2.Rows[LvTable2.Rows.Count - 1][5] = LvReader.GetValue(5).ToString();



                    //LvList.Add(LvPos);
                }
                return LvTable2;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
